<?php

namespace App\Traits;

trait RetrunService
{

    //成功返回
    public static function success($data = [], $code = 200,$message='')
    {
        if($message == '')$message = config('errorcode.code')[(int) $code];

        return response()->json([
            'status'  => true,
            'code'    => $code,
            'message' => $message,
            'data'    => $data,
        ]);
    }

    //失败返回
    public static function fail($message = '', $code=500)
    {
        if($message == '')$message = config('errorcode.code')[(int) $code];

        return response()->json([
            'status'  => false,
            'code'    => $code,
            'message' => $message,
        ]);
    }

}
